package com.ruoyi.hr.controller.hr.bginfo;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.hr.domain.Authority;
import com.ruoyi.hr.service.AuthorityService;
import com.ruoyi.hr.service.bginfo.BgTitleService;
import com.ruoyi.hr.service.bginfo.BgWorkService;
import com.ruoyi.hr.util.BaseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zeo
 * @explain 职称/资格证书
 * @date 2020/3/30
 */

@Controller
@RequestMapping("/bgInfo/title")
public class TitleController extends BaseController {

    @Autowired
    BgTitleService bgTitleService;

    @Autowired
    AuthorityService authorityService;

    private String prefix = "hr/bginfo/title";

    /**
     * 跳转分页页面
     */
    @GetMapping()
    public String title() {
        return prefix + "/title";
    }

    @RequestMapping("/findDataList")
    @ResponseBody
    public TableDataInfo findDataList(@RequestParam Map map) {
        Authority authority = authorityService.findAuthorAndIsAdmin();
        startPage();
        return getDataTable(bgTitleService.findDataList(map, authority));
    }

    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("emp", bgTitleService.findDataById(id));
        return prefix + "/edit";
    }

    @RequestMapping("/edit")
    @ResponseBody
    public AjaxResult edit(@RequestParam Map map) {
        return toAjax(bgTitleService.edit(map));
    }

    @RequestMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(bgTitleService.remove(ids));
    }

    @RequestMapping("/procedure")
    @ResponseBody
    public BaseResult procedure(String allId){
        return bgTitleService.procedure(allId);
    }

    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    @RequestMapping("/add")
    @ResponseBody
    public AjaxResult add(@RequestParam Map map){
        return  toAjax(bgTitleService.add(map));
    }
}
